package ar.edu.unq.wannaplay.ws;

import java.util.List;

import javax.jws.WebService;

import org.springframework.stereotype.Controller;

import ar.edu.unq.wannaplay.dtos.ClientDTO;
import ar.edu.unq.wannaplay.exceptions.BlankStringException;
import ar.edu.unq.wannaplay.exceptions.EmailSyntaxException;
import ar.edu.unq.wannaplay.services.ClientService;

@Controller
@WebService(endpointInterface = "ar.edu.unq.wannaplay.ws.ClientWebService")
public class ClientWebServiceImpl implements ClientWebService {

    private ClientService clientService;

    @Override
    public String helloWorld(final String mess, final String remess) {
        return "hello! " + mess + "," + remess;
    }

    public void setClientService(final ClientService clientService) {
        this.clientService = clientService;
    }

    public ClientService getClientService() {
        return clientService;
    }

    @Override
    public List<ClientDTO> getAll() {
        return this.getClientService().findAllDTOs();
    }

    @Override
    public int numberOfClients() {
        return this.getAll().size();
    }

    @Override
    public String addClient(final String name, final String email, final String address, final String town) {
        try {
            clientService.saveClient(name, email, address, town);
        } catch (BlankStringException e) {
            throw new UnsupportedOperationException(e);
        } catch (EmailSyntaxException e) {
            throw new UnsupportedOperationException(e);
        }
        return name + email + address + town;
    }

}
